/*
 * Timer.java
 *
 * Created on 19 de Dezembro de 2004, 11:00
 */

package ceirinhashls.gui;

import java.util.Timer;
import java.util.TimerTask;

/**
 *
 * @author  botelhodaniel
 */
public class Schedule /*implements Runnable*/{
    private MainFrame mf;
    private Timer timer;
    private long time;
    private boolean isAlive;
    /** Creates a new instance of Timer */
    public Schedule(MainFrame mf) {
        this.mf = mf;
        isAlive=false;
    }
    public void start(){
        isAlive= true;
        time = ScheduleDialog.getTime();
        System.out.println(time);
        timer = new Timer();
        timer.scheduleAtFixedRate(new RemindTask(), new java.util.Date(System.currentTimeMillis()+time), time);
    }
    
    public void end(){
        isAlive= false;
        timer.cancel();
    }
    
    public boolean isAlive(){
        return isAlive;
    }
    
    class RemindTask extends TimerTask {
        public void run() {
            System.out.println("Time's up!");
            mf.timeReached();
        }
    }
    
}
